using System;
using System.Data;
using NHibernate.Cfg;
using NHibernate;

namespace Serpis
{
	public class AppDbConnection
	{
		private static AppDbConnection instance = new AppDbConnection();
		private Configuration configuration;
		private ISessionFactory sessionFactory;
		
		//Singleton
		private AppDbConnection()
		{
		}
		
		public static AppDbConnection Instance
		{
			get {return instance;}
		}
		
		public Configuration Configuration 
		{
			get 
			{
				if (configuration == null) 
				{
					configuration= new Configuration();
					configuration.Configure();
				}
				return configuration;
			}
		}

		public ISessionFactory SessionFactory 
		{
			get
			{
				if (sessionFactory == null)
				{
					sessionFactory = configuration.BuildSessionFactory();
				}
				return sessionFactory;
			}
		}
		
		public void Close()
		{
			sessionFactory.Close();
		}
	}
}